package com.changgou.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changgou.framework.entity.PageResult;
import com.changgou.goods.dao.SpecDao;
import com.changgou.goods.service.SpecService;
import com.haha.goods.entity.Spec;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.zip.ZipEntry;

/**
 * @author Yang
 * @date 2020/11/7
 */
@Service
public class SpecServiceImpl extends ServiceImpl<SpecDao, Spec> implements SpecService {

    @Override
    public PageResult findPage(Spec spec, int page, int size) {
        QueryWrapper<Spec> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(spec)){
            queryWrapper.eq(spec.getId()!=null,"id",spec.getId());
            queryWrapper.eq(!StringUtils.isEmpty(spec.getOptions()),"options",spec.getOptions());
            queryWrapper.eq(spec.getSeq()!=null,"seq",spec.getSeq());
            queryWrapper.eq(spec.getTemplateId()!=null,"template_id",spec.getTemplateId());
            queryWrapper.like(!StringUtils.isEmpty(spec.getName()),"name",spec.getName());
        }
        Integer count = baseMapper.selectCount(queryWrapper);
        int offset = (page-1)*size;
        List<Spec> specList = baseMapper.findPage(queryWrapper,offset, size);
        return null;
    }

    @Override
    public List<Spec> findByCategoryId(Integer categoryid) {
        return baseMapper.findByCategoryId(categoryid);
    }
}
